package com.xiaoshuidi.cloud.module.rooms.utils;


import com.xiaoshuidi.cloud.module.rooms.enums.TowardEnum;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
 * 枚举类工具
 * @Author Summer
 * @date 2023/5/22
 */
public class EnumUtil {
    public static boolean isInclude(Class<?> c, String methodName,String value) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        boolean include = false;
        if (c.isEnum()) {
            Method method = c.getMethod(methodName);
            Object[] enumConstants = c.getEnumConstants();
             for (Object obj:enumConstants){
                 Enum e = (Enum) obj;
                  String result = (String) method.invoke(e);
                  if (result.equals(value)){
                      include=true;
                      break;
                  }
             }
        }
        return include;
    }

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
         boolean b = isInclude(TowardEnum.class, "getName","朝南");
        System.out.println(b);
    }
}
